package com.youlv.yl.controller;

import com.youlv.yl.util.AliOssUtils;
import com.youlv.yl.util.DateUtils;
import com.youlv.yl.util.FileUtils;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author fenghe
 * @date 2021/12/28 19:18
 */
@RestController
@RequestMapping("/api/oss/")
@Api(value = "实现文件上传到云的相关操作", tags = "实现文件上传到云的相关操作")
public class OssController {

    @PostMapping("upload.do")
    public String upload(@RequestPart("file") MultipartFile file) throws IOException {
        String fn = FileUtils.rename(file.getOriginalFilename());
        return AliOssUtils.upload(fn, file.getBytes(), DateUtils.getYearTime(1));
    }
}
